<!--#
layout("/layouts/platform.html"){
#-->
<style>
    .el-upload input[type=file] {
        display: none;
    }

    .el-upload__text {
        color: #606266;
        font-size: 14px;
        text-align: center;
    }
</style>
<div id="app"  v-cloak>
    <el-row class="header navbar bg-white">
        <div class="btn-group tool-button" style="line-height: 50px;">
            实验室名称：<el-input placeholder="实验室名称" v-trim v-model="pageForm.name" size="mini" style="width:180px;" clearable></el-input>
            专业领域：<el-input placeholder="专业领域" v-trim v-model="pageForm.major" size="mini" style="width:180px;" clearable></el-input>
            <el-button slot="append" icon="el-icon-search" size="mini" @click="doSearch" circle></el-button>
        </div>
        <div class="pull-right offscreen-right" style="margin-right: 20px;line-height: 50px;">
             <el-tooltip class="item" effect="dark" content="新增">
                    <el-button type="primary" icon="el-icon-plus"  size="mini" @click="openAddDialog" circle></el-button>
             </el-tooltip>
        </div>
    </el-row>

    <el-row class="el-table-container">
        <el-table :data="tableData" @sort-change='pageOrder' height="520"  border size="small" header-align="center"  style="width: 100%" @selection-change="handleSelectionChange">
            <el-table-column
                    fixed="left"
                    prop="note"
                    label="操作"
                    width="120" header-align="center" align="center" >
                <template slot-scope="scope">
                    <el-dropdown @command="dropdownCommand">
                        <el-button size="mini">
                            <i class="ti-settings"></i>
                            <span class="ti-angle-down"></span>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item divided v-if="scope.row.opby == '${userId}'" :command="{type:'edit',row:scope.row}">
                                修改
                            </el-dropdown-item>
                            <el-dropdown-item divided v-if="scope.row.opby == '${userId}'" :command="{type:'delete',row:scope.row}">
                                删除
                            </el-dropdown-item>
                            <el-dropdown-item divided :command="{type:'detail',row:scope.row}">
                                详情
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </el-table-column>
            <el-table-column fixed="left" sortable="custom" prop="name" label="实验室名称" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="major" label="专业领域" width="200px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="managername" label="实验室主任" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column sortable="custom" prop="deptsname" label="使用部门" width="220px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="address" label="实验室地点" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
            <el-table-column  prop="remark" label="备注" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
        </el-table>
    </el-row>
    <el-row class="el-pagination-container">
        <el-pagination @size-change="pageSizeChange" @current-change="pageNumberChange" :current-page="pageForm.pageNumber" :page-sizes="[10, 20, 30, 50]"
                       :page-size="pageForm.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageForm.totalCount">
        </el-pagination>
    </el-row>

    <el-dialog :close-on-click-modal="false" append-to-body   title="实验室信息"  :visible.sync="addDialogVisible" width="1200px">
        <el-form id="addForm"  :rules="formRules" :model="formData" ref="addForm"  size="small" label-width="120px" >
            <el-row :gutter="20" border>
                <el-col :span="8">
                    <el-form-item prop="name" label="实验室名称" >
                        <el-input maxlength="16"v-trim v-model="formData.name" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="major" label="专业领域">
                        <el-input maxlength="16"v-trim v-model="formData.major" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="managerBy" label="实验室主任" >
                        <el-cascader v-model="formData.managerBy" :options="allMap.userOptions" placeholder="搜索" ref="manager" filterable collapse-tags style="width:180px;"></el-cascader>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="depts" label="使用部门" >
                        <el-cascader v-model="formData.depts" :options="allMap.unitOptions" :props="props" ref="depts"  style="width:180px;"></el-cascader>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="address" label="实验室地点">
                        <el-input maxlength="125"v-trim v-model="formData.address" type="text"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="remark" label="备注" >
                        <el-input maxlength="125"v-trim v-model="formData.remark" type="textarea"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="filePath" label="相关附件">
                        <el-upload
                                class="upload-demo"
                                name="Filedata"
                                action="${base}/open/file/upload/file1"
                                :on-remove="handleRemove"
                                :before-remove="beforeRemove"
                                :on-success="handleSuccess"
                                multiple
                                :limit="3"
                                :on-exceed="handleExceed"
                                :file-list="fileList">
                            <el-button size="small" type="primary">点击上传</el-button>
                        </el-upload>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="code" label="实验室设备" >
                        <el-button type="primary" size="mini" @click="openEquipment" plain>选择设备</el-button>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item prop="code" label="实验室人员" >
                        <el-button type="primary" size="mini" @click="openUser" plain>选择人员</el-button>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-table :data="formData.equipments" border style="width: 80%">
                        <el-table-column prop="code" label="设备编号"></el-table-column>
                        <el-table-column prop="name" label="设备名称"></el-table-column>
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button size="mini" type="danger" @click="handleEquipmentDelete(scope.$index, scope.row)">移除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>

                <el-col :span="12">
                    <el-table :data="formData.users" border style="width: 80%">
                        <el-table-column prop="unitName" label="部门"></el-table-column>
                        <el-table-column prop="username" label="姓名"></el-table-column>
                        <el-table-column prop="mobile" label="手机"></el-table-column>
                        <el-table-column label="操作">
                            <template slot-scope="scope">
                                <el-button size="mini" type="danger" @click="handleUserDelete(scope.$index, scope.row)">移除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="addDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="doAdd">确 定</el-button>
        </span>
    </el-dialog>


    <el-dialog title="选择设备" :visible.sync="visibleEquipment" width="80%"  append-to-body>
        <el-row class="bg-white">
            <div class="btn-group tool-button" style="line-height: 50px;">
                <el-input placeholder="设备编号" v-trim v-model="pageFormEquipment.code" size="mini" style="width:180px;" clearable></el-input>
                <el-input placeholder="设备名称" v-trim v-model="pageFormEquipment.name" size="mini" style="width:180px;" clearable></el-input>
                <el-button slot="append" icon="el-icon-search" size="mini" @click="doSearchEquipment" circle></el-button>
            </div>
        </el-row>
        <el-row>
            <el-table :data="tableDataEquipment" @sort-change='pageOrderEquipment' height="400"  border
                      ref="multipleTableEquipment"
                      size="small" header-align="center"  style="width: 100%" @selection-change="handleSelectionChange" row-key="id">
                <el-table-column type="selection" reserve-selection="true"  label="选择" width="55px;" header-align="center" :selectable="selecEquipmentTable" align="center"></el-table-column>
                <el-table-column fixed="left" sortable="custom" prop="code" label="设备编号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column fixed="left" sortable="custom" prop="name" label="设备名称" width="200px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="model" label="规格型号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="detectionrange" label="检测范围" width="220px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="accuracy" label="精度要求" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="factorycode" label="出厂编号" width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="number" label="数量（台/套）" min-width="130px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="company" label="制造厂商" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="purchaseprice" label="购置价格（元）" min-width="130px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column sortable="custom" prop="purchasedate" label="购置日期" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="calculate" label="计量方式" min-width="120px;" header-align="center" align="center" show-overflow-tooltip>
                    <template slot-scope="scope" >{{getDict(scope.row.calculate,allMap.calculateMap)}}</template>
                </el-table-column>
                <el-table-column  prop="calculateunit" label="计量单位" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="calculatecycle" label="计量周期" min-width="120px;" header-align="center" align="center" show-overflow-tooltip>
                    <template slot-scope="scope" >{{scope.row.calculatecycle}}{{getDict(scope.row.calculatecycletype,allMap.calculateCycleTypeMap)}}</template>
                </el-table-column>
                <el-table-column  sortable="custom" prop="calculatedate" label="下次计量日期" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="depositadress" label="存放地点" min-width="220px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="managername" label="设备管理人" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="applyname" label="使用部门" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="classification" label="分类情况" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="importedflag" label="是否进口设备" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="assetcode" label="资产编号" min-width="120px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="supplyphone" label="供货商联系电话" min-width="150px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>
                <el-table-column  prop="remark" label="备注" min-width="320px;" header-align="center" align="center" show-overflow-tooltip></el-table-column>

            </el-table>
        </el-row>
        <el-row class="el-pagination-container">
            <el-pagination @size-change="pageSizeChangeEquipment" @current-change="pageNumberChangeEquipment" :current-page="pageFormEquipment.pageNumber" :page-sizes="[10, 20, 30, 50]"
                           :page-size="pageFormEquipment.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageFormEquipment.totalCount">
            </el-pagination>
        </el-row>

        <span slot="footer" class="dialog-footer">
            <el-button @click="visibleEquipment = false">取 消</el-button>
            <el-button type="primary" @click="setEquipment">确 定</el-button>
        </span>
    </el-dialog>



    <el-dialog title="选择人员" :visible.sync="visibleUser" width="80%"  append-to-body>
        <el-row class="bg-white">
            <div class="btn-group tool-button" style="line-height: 50px;">
                <el-input placeholder="姓名" v-trim v-model="pageFormUser.username" size="mini" style="width:180px;" clearable></el-input>
                <el-button slot="append" icon="el-icon-search" size="mini" @click="doSearchUser" circle></el-button>
            </div>
        </el-row>
        <el-row>
            <el-table :data="tableDataUser" @sort-change='pageOrderUser' height="400"  border
                      ref="multipleTableUser"
                      size="small" header-align="center"  style="width: 100%" @selection-change="handleSelectionChangeUser" row-key="id">
                <el-table-column type="selection" reserve-selection="true" label="选择" width="55px;" header-align="center" :selectable="selecUserTable" align="center"></el-table-column>
                <el-table-column prop="unit" label="部门">
                    <template slot-scope="scope">
                            <span v-if="scope.row.unit!=null">
                                {{scope.row.unit.name}}
                            </span>
                    </template>
                </el-table-column>
                <el-table-column prop="username" label="姓名" ></el-table-column>
                <el-table-column prop="mobile" label="手机号" ></el-table-column>
            </el-table>
        </el-row>
        <el-row class="el-pagination-container">
            <el-pagination @size-change="pageSizeChangeUser" @current-change="pageNumberChangeUser" :current-page="pageFormUser.pageNumber" :page-sizes="[10, 20, 30, 50]"
                           :page-size="pageFormUser.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageFormUser.totalCount">
            </el-pagination>
        </el-row>

        <span slot="footer" class="dialog-footer">
            <el-button @click="visibleUser = false">取 消</el-button>
            <el-button type="primary" @click="setUser">确 定</el-button>
        </span>
    </el-dialog>

    <el-drawer :wrapperClosable="false" title="详情" :visible.sync="detailDialogVisible" direction="rtl" size="80%"  destroy-on-close>
        <el-form :model="detailFormData" size="small" label-width="120px" class="overflowAuto">
            <el-row :gutter="20" border>
                <el-col :span="8">
                    <el-form-item prop="name" label="实验室名称" >
                        {{detailFormData.name}}
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="major" label="专业领域">
                        {{detailFormData.major}}
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="managerBy" label="实验室主任" >
                        {{detailFormData.managerName}}
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item prop="depts" label="使用部门" >
                        {{detailFormData.deptsName}}
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="address" label="实验室地点">
                        {{detailFormData.address}}
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item prop="remark" label="备注" >
                        {{detailFormData.remark}}
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="相关附件" >
                        <template v-for="item in fileList">
                            <el-link :href="AppFile+item.response.data.filePath" target="_blank">{{item.name}}</el-link><br>
                        </template>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-table :data="detailFormData.equipments" border style="width: 80%">
                        <el-table-column prop="code" label="设备编号"></el-table-column>
                        <el-table-column prop="name" label="设备名称"></el-table-column>
                        </el-table-column>
                    </el-table>
                </el-col>
                <el-col :span="12">
                    <el-table :data="detailFormData.users" border style="width: 80%">
                        <el-table-column prop="unitName" label="部门"></el-table-column>
                        <el-table-column prop="username" label="姓名"></el-table-column>
                        <el-table-column prop="mobile" label="手机"></el-table-column>
                    </el-table>
                </el-col>
            </el-row>
        </el-form>
    </el-drawer>
</div>
<style scoped>
    .el-table--border th.gutter:last-of-type {
        display: block !important;
        width: 17px !important;
    }

    .overflowAuto {
        padding-left: 20px;
        overflow-y: auto;
        position: absolute;
        width: 100%;
        height: 100%;
    }
    .overflowAuto::-webkit-scrollbar {
        height: 6px;
        width: 6px;
    }
    .overflowAuto::-webkit-scrollbar-thumb {
        background: rgb(224, 214, 235);
    }

</style>
<script>
    var allMap = {unitOptions:${unitOptions},userOptions:${userOptions}}
    new Vue({
        el: "#app",
        data: function () {
            return {
                allMap:allMap,
                tableData: [],
                addDialogVisible:false,
                detailDialogVisible:false,
                pageForm: {},
                formData: {},
                detailFormData:{},
                formRules: {
                    name: [{required: true, message: '设备名称', trigger: ['blur', 'change']}],
                    mobile:[ {pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号码'}],
                },
                props: { multiple: true },
                tableDataEquipment: [],
                pageFormEquipment: {},
                visibleEquipment:false,
                multipleSelectionEquipment:[],


                tableDataUser: [],
                pageFormUser: {},
                visibleUser:false,
                multipleSelectionUser:[],
                AppFile:"${AppFileDomain}${AppUploadBase}",
                fileList: []
            }
        },
        methods: {
            doAdd: function () {
                var self = this;
                self.$refs["addForm"].validate(function (valid) {
                    if (valid) {
                        if(nONull(self.formData.managerBy)){
                            self.formData.managerName = "";
                            for(var i =0 ;i<self.formData.managerBy.length;i++){
                                self.formData.managerName += self.$refs['manager'].getCheckedNodes()[i].label;
                                if(i<(self.formData.managerBy.length -1 )){
                                    self.formData.managerName +=",";
                                }
                            }
                            self.formData.managerBy=self.formData.managerBy.join(",");
                        }
                        if(nONull(self.formData.depts)){
                            self.formData.deptsName = "";
                            for(var i =0 ;i<self.formData.depts.length;i++){
                                self.formData.deptsName += self.$refs['depts'].getCheckedNodes()[i].label;
                                if(i<(self.formData.depts.length -1 )){
                                    self.formData.deptsName +=",";
                                }
                            }
                            self.formData.depts=self.formData.depts.join(",");
                        }
                        var url = "/platform/bus/laboratory/addDo";
                        if(nONull(self.formData.id)){
                            url = "/platform/bus/laboratory/editDo";
                        }
                        $.post(base + url, {laboratory:JSON.stringify(self.formData)}, function (data) {
                            if (data.code == 0) {
                                self.$message({
                                    message: data.msg,
                                    type: 'success'
                                });
                                self.addDialogVisible = false;
                                self.pageData();//添加失败也可以入库,所以加载一下看看
                            } else {
                                self.$message({
                                    message: data.msg,
                                    type: 'error'
                                });
                                if(nONull(self.formData.managerBy)){self.formData.managerBy=self.formData.managerBy.split(",");}
                                if(nONull(self.formData.depts)){self.formData.depts=self.formData.depts.split(",");}
                            }
                        }, "json");
                    }
                });
            },
            openAddDialog:function(){
                this.addDialogVisible=true;
                this.formData ={equipments:[],users:[]}//打开新增窗口,表单先清空
                this.fileList= [];
                if (this.$refs["addForm"])
                    this.$refs["addForm"].resetFields();
            },
            pageOrder: function (column) {//按字段排序
                this.pageForm.pageOrderName = column.prop;
                this.pageForm.pageOrderBy = column.order;
                this.pageData();
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/platform/bus/laboratory/data", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },

            dropdownCommand: function (command) {//监听下拉框事件
                var self = this;
                if ("delete" == command.type) {
                    self.$confirm('此操作将删除 ' + command.row.name, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                $.post(base + "/platform/bus/laboratory/delete/" + command.row.id, {}, function (data) {
                                    if (data.code == 0) {
                                        self.$message({
                                            message: data.msg,
                                            type: 'success'
                                        });
                                        self.doSearch();
                                    } else {
                                        self.$message({
                                            message: data.msg,
                                            type: 'error'
                                        });
                                    }
                                }, "json");
                            }
                        }
                    });
                }
                if("edit" == command.type){//修改
                    //根据id获取数据
                    $.post(base + "/platform/bus/laboratory/detail/" + command.row.id, {}, function (data) {
                        if (data.code == 0) {
                            self.formData =  data.data;
                            if(nONull(self.formData.managerBy)){self.formData.managerBy=self.formData.managerBy.split(",");}
                            if(nONull(self.formData.depts)){self.formData.depts=self.formData.depts.split(",");}
                            self.setFile(self.formData.fileId);
                        } else {
                            self.$message({message: data.msg,type: 'error'});
                        }
                    }, "json");
                    //打开窗口
                    this.addDialogVisible=true;
                }
                if("detail" == command.type){//详情
                    //根据id获取数据
                    $.post(base + "/platform/bus/laboratory/detail/" + command.row.id, {}, function (data) {
                        if (data.code == 0) {
                            self.detailFormData =  data.data;
                            self.setFile(self.detailFormData.fileId);
                        } else {
                            self.$message({message: data.msg,type: 'error'});
                        }
                    }, "json");
                    //打开窗口
                    this.detailDialogVisible=true;
                }
            },
            getDict: function (val,map) {
                if (val!= null && val!=undefined &&val!="" &&val!="null" &&val!="undefined" && map!=null && map !=undefined){
                    var str = val.split(",");
                    var strname="";
                    for (var a=0;a<str.length;a++){
                        strname+=map[str[a]];
                        if(strname == null){
                            alert(1)
                        }
                        if(a<(str.length-1)){
                            strname+="/";
                        }
                    }
                    return strname;
                }
                return "";
            },
            openEquipment:function(){
                this.visibleEquipment = true;
                this.multipleSelectionEquipment = [];
                this.$nextTick(() => {
                    this.$refs.multipleTableEquipment.clearSelection();
                });
                this.doSearchEquipment();
            },
            pageOrderEquipment: function (column) {//按字段排序
                this.pageFormEquipment.pageOrderName = column.prop;
                this.pageFormEquipment.pageOrderBy = column.order;
                this.pageDataEquipment();
            },
            pageNumberChangeEquipment: function (val) {//页码更新操作
                this.pageFormEquipment.pageNumber = val;
                this.pageDataEquipment();
            },
            pageSizeChangeEquipment: function (val) {//分页大小更新操作
                this.pageFormEquipment.pageSize = val;
                this.pageDataEquipment();
            },
            pageDataEquipment: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/platform/bus/equipment/data", self.pageFormEquipment, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableDataEquipment = data.data.list;
                        self.pageFormEquipment.totalCount = data.data.totalCount;
                        //回显选中self.formData.inventorys

                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            doSearchEquipment: function () {
                this.pageFormEquipment.pageNumber = 1;
                this.pageDataEquipment();
            },
            handleSelectionChange: function (val) {
                this.multipleSelectionEquipment=val;
            },
            setEquipment:function(){
                var self = this;
                if(self.multipleSelectionEquipment.length==0){
                    self.$message({message: "请选择设备！",type: 'error'});
                    return;
                }
                for(var item of self.multipleSelectionEquipment){
                    var equipments={
                        equipmentId:item.id,
                        name:item.name,
                        code:item.code
                    };
                    self.formData.equipments.push(equipments);
                }
                self.visibleEquipment = false;
            },
            //判断勾选
            selecEquipmentTable(row, index) {
                var res = true;
                this.formData.equipments.forEach((item)=>{
                    if (item.equipmentId == row.id) {
                        res =  false; // 禁用
                    }
                })
                return res;
            },
            handleEquipmentDelete(index, row) {
                var self = this;
                if (row.id) {
                    self.$confirm('此操作将移除设备：' + row.name, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                $.post(base + "/platform/bus/laboratory/equipment/delete/" + row.id, {}, function (data) {
                                    if (data.code == 0) {
                                        self.$message({message: data.msg, type: 'success'});
                                        self.formData.equipments.splice(index, 1);
                                    } else {
                                        self.$message({message: data.msg, type: 'error'});
                                    }
                                }, "json");
                            }
                        }
                    });
                } else {
                    self.formData.equipments.splice(index, 1);
                }
            },




            openUser:function(){
                if(nONull(this.formData.depts)){
                    this.pageFormUser.searchUnit = this.formData.depts.join(",");
                }
                else{
                    this.$message({message: "请先选择使用部门！",type: 'error'});
                    return ;
                }
                this.visibleUser = true;
                this.multipleSelectionUser = [];
                this.$nextTick(() => {
                    this.$refs.multipleTableUser.clearSelection();
                });
                this.doSearchUser();
            },
            pageOrderUser: function (column) {//按字段排序
                this.pageFormUser.pageOrderName = column.prop;
                this.pageFormUser.pageOrderBy = column.order;
                this.pageDataUser();
            },
            pageNumberChangeUser: function (val) {//页码更新操作
                this.pageFormUser.pageNumber = val;
                this.pageDataUser();
            },
            pageSizeChangeUser: function (val) {//分页大小更新操作
                this.pageFormUser.pageSize = val;
                this.pageDataUser();
            },
            pageDataUser: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/platform/sys/msg/user_data", self.pageFormUser, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code == 0) {
                        self.tableDataUser = data.data.list;
                        self.pageFormUser.totalCount = data.data.totalCount;
                        //回显选中self.formData.inventorys

                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            doSearchUser: function () {
                this.pageFormUser.pageNumber = 1;
                this.pageDataUser();
            },
            handleSelectionChangeUser: function (val) {
                this.multipleSelectionUser=val;
            },
            setUser:function(){
                var self = this;
                if(self.multipleSelectionUser.length==0){
                    self.$message({message: "请选择人员！",type: 'error'});
                    return;
                }
                for(var item of self.multipleSelectionUser){
                    var user={
                        userId:item.id,
                        username:item.username,
                        unitName:item.unit.name,
                        mobile:item.mobile,
                    };
                    self.formData.users.push(user);
                }
                self.visibleUser = false;
            },
            //判断勾选
            selecUserTable(row, index) {
                var res = true;
                this.formData.users.forEach((item)=>{
                    if (item.userId == row.id) {
                        res =  false; // 禁用
                    }
                })
                return res;
            },
            handleUserDelete(index, row) {
                var self = this;
                if (row.id) {
                    self.$confirm('此操作将移除人员：' + row.username, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                $.post(base + "/platform/bus/laboratory/user/delete/" + row.id, {}, function (data) {
                                    if (data.code == 0) {
                                        self.$message({message: data.msg, type: 'success'});
                                        self.formData.users.splice(index, 1);
                                    } else {
                                        self.$message({message: data.msg, type: 'error'});
                                    }
                                }, "json");
                            }
                        }
                    });
                } else {
                    self.formData.users.splice(index, 1);
                }
            },
            handleRemove: function (file, fileList) {
                var self = this;
                var thisData = file.response.data;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/open/file/upload/delFile/"+thisData.id, {}, function (data) {
                    if (data.code == 0) {
                        sublime.closeLoadingbar();//关闭loading
                        self.$message({message: data.msg,type: 'success'});
                        if(self.formData.fileId && self.formData.fileId!=""){
                            if(self.formData.fileId.split(",").length>1){
                                self.formData.fileId = self.formData.fileId.replace(","+thisData.id,"");
                            }else{
                                self.formData.fileId = "";
                            }
                        }
                    } else {
                        self.$message({message: data.msg,type: 'error'});
                    }
                }, "json");
            },
            handleExceed: function (files, fileList) {
                this.$message.warning(`当前限制选择 3 个文件，本次选择了 `+files.length+` 个文件，共选择了 `+(files.length + fileList.length)+` 个文件`);
            },
            beforeRemove: function (file) {
                return this.$confirm(`确定移除 `+file.name+`？`);
            },
            handleSuccess:function(file){
                if(this.formData.fileId && this.formData.fileId!=""){
                    this.formData.fileId += ","+file.data.id;
                }else{
                    this.formData.fileId = file.data.id;
                }
            },
            setFile: function (fileId) {
                var self = this;
                self.fileList=[];
                if(fileId && fileId!=""){
                    var fileIds = fileId.split(",")
                    for(var i=0;i<fileIds.length;i++){
                        $.post(base + "/open/file/upload/getFile/"+fileIds[i], {}, function (data) {
                            if (data.code == 0) {
                                var file = {
                                    name:data.data.fileBeforeName,
                                    response:{
                                        data:data.data
                                    }
                                }
                                self.fileList.push(file);
                            } else {
                                self.$message({message: data.msg,type: 'error'});
                            }
                        }, "json");
                    }

                }
            }
        },
        created: function () {
            this.doSearch();
        }
    });

    function nONull(val){
        if (val!= null && val!=undefined &&val!="" &&val!="null" &&val!="undefined" ){
            return true;
        }else{
            return false;
        }
    }
</script>
<!--#
}
#-->
